<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
        var combine = function (n, k) {

            let res = [];
            let arr = [];
            let numbers = [];
            for (let i = 0; i < n; i++) {
                numbers.push(i + 1);
            }
            const func = function (n, k, start) {
                if (arr.length === k) {
                    console.log('arr', arr);
                    res.push([...arr]);
                    console.log('res', res)
                    return;
                }
                for (let i = start; i < numbers.length; i++) {
                    arr.push(numbers[i]);
                    func(n, k, i + 1);
                    arr.pop();
                }

            }
            func(n, k, 0);//求1到n的所有k个数的组合
            console.log('res???', res)
            return res;


        };
        
        combine(4, 2);

    </script>
</body>

</html>